#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e5+50;

int a[N], n;
LL x;
LL cnt[70];
unordered_map<int, int> mp;


int main(int argc, char const *argv[])
{
	for (int i=0; i<=30; ++i)
		mp[1 << i] = i;

	int t;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%lld%d", &x, &n);
		memset(cnt, 0, 8 * 64);
		LL sum = 0;
		for (int i=0; i<n; ++i)
		{
			scanf("%d", &a[i]);
			sum += a[i];
			a[i] = mp[a[i]];
			++cnt[a[i]];
		}
		if (sum < x)
		{
			puts("-1");
			continue;
		}
		vector<int> ans;
		for (int i=0; i<62; ++i)
		{
			if ((x >> i) & 1)
			{
				ans.push_back(i);
			}	
		}

		int Ans = 0;
		for (int x : ans)
		{
			for (int j=0; j<x; ++j)
			{
				cnt[j+1] += cnt[j]/2;
				cnt[j] -= cnt[j]/2*2;
			}
			int candi = -1;
			for (int j=x; j<64; ++j)
			{
				if (cnt[j] > 0)
				{
					candi = j;
					break;
				}
			}
			if (candi == -1)
			{
				Ans = -1;
				break;
			}
			Ans += abs(candi - x);
			for (int i=x; i<candi; ++i)
				++cnt[i];
			--cnt[candi];
			dbg(x, cnt[x], candi);
		}
		printf("%d\n", Ans);
	}
	



	return 0;
}